package 笔试;
import java.util.Arrays;
import java.util.Scanner;
public class 美团 {


    private static int max=0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];//表示颜色
        int[] aa = new int[n+1];//表示此节点状态  0表示无子节点  >0表示是好节点 <0表示有子节点但不是好节点
        int b=0,h=0;
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            int q = sc.nextInt();
            if(q!=0){
                if(a[i]!=a[q]){
                    if(a[q]==0){
                        aa[q]+=200000001;
                    }
                    aa[q]++;
                }else{
                    aa[q]-=20000;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            if(aa[i]>=0){
                if(a[i]==0){
                    b++;
                }else {
                    h++;
                }
            }
        }
        System.out.println(b+" "+h);

    }

    private static void 三(Scanner sc, int n) {
        int m = sc.nextInt();
        int[][] d = new int[n][2];
        for (int i = 0; i < n; i++) {
            d[i][0] = sc.nextInt();
            d[i][1] = sc.nextInt();
        }
        san(d,0,0,0);
        System.out.println(max);
    }

    private static void san(int[][] d,int k,int c,int g) {//k 为此材料是否用了  c：多少为顾客满意 g到哪一个顾客了
        if(g==d.length){
            if(c>max){max=c;}
            return;
        }
        if(((1<<d[g][0])&k)==0&&((1<<d[g][1])&k)==0){
            san(d,k,c,g+1);
            k+=1<<d[g][0];
            k+=1<<d[g][1];
            san(d,k,c+1,g+1);
        }else {
            san(d,k,c,g+1);
        }


    }

    private static void 四(Scanner sc, int n, int m) {
        int[] ms = new  int[m];

        for (int i = 0; i < m; i++) {
            ms[i] = sc.nextInt();
        }
        int[] ms1 = new  int[n +1];
        ms1[0]=1;
        int k=0;
        int i=1;
        while (i < m){
            if(ms[i]==ms1[0]){
                k++;
                ms1[0]=0;
                do{
                    if(ms1[ms[i]]==0){
                        if(ms1[0]< n -1){
                            ms1[ms[i]]=1;
                            ms1[0]++;
                        }else {
                            ms1 = new int[n +1];
                            ms1[0]=ms[i];
                            i--;
                            break;
                        }
                    }
                    i++;
                }while (i< m);
            }
            i++;
        }

        System.out.println(k);
    }

    private static void TWO(Scanner sc, int n) {
        int[] s = new int[n];
        int k=0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            int q=1;
            int j=i+1;
            do{
                j--;
                q*=s[j];
                if(q>0){
                    k++;
                }
            }while (j>0);
        }
        System.out.println(k);
    }

    private static void ONE(Scanner sc, int n) {
        for (int i = 0; i < n; i++) {
            int m = sc.nextInt();
            if(m%11==0){
                System.out.println("yes");
            }else{
                int k=0;
                while (m>0){
                    if(m%10==1){
                        k++;
                        if(k>1){
                            break;
                        }
                    }
                    m/=10;
                }
                if(k>1){
                    System.out.println("yes");
                }else {
                    System.out.println("no");
                }
            }
        }
    }
}
